//
//  THWKWebView.h
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 BaseBusiness. All rights reserved.
//

#import <WebKit/WebKit.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface THWKWebView : WKWebView

@property (nonatomic) BOOL isNewLink;

@property (nonatomic) BOOL injectNativeFunction;

///兼容UIWebview同名方法
@property (nonatomic, readonly, strong) NSURLRequest *request;

/**
 默认的cookie名称列表，创建webview时从NSHTTPCookieStorage中注入
 */
@property (class,assign) NSArray<NSString *> * defaultCookieNameList;
///外部注入js脚本
@property (class,assign) NSArray<NSString *> * jsHandlerNameList;
///设置cookie校验白名单
@property (class,assign) NSArray<NSString *> * defaultCookieWhiteNameList;

/**
 外部代理
 */
@property (weak,nonatomic) id<WKNavigationDelegate> delegate;

/**
 获取实例

 @return KWWKWebView实例，iOS9以下系统兼容性不好，返回nil
 */
+ (THWKWebView *)getInstance;

///cookie列表 优先级高于defaultCookieNameList
@property (strong, nonatomic) NSArray<NSString *> * cookieNameList;
///js列表 jsFileList会覆盖jsHandlerNameList中的同名方法
@property (strong, nonatomic) NSArray<NSString *> * jsFileList;

/**
 设置H5调用原生白名单

 @param classList 白名单类列表
 @param objectList 白名单对象列表
 */
- (void)setWhiteClassList:(NSArray<Class> *)classList whiteObjectList:(NSArray<NSObject *> *)objectList;

/**
 页面进入
 */
- (void)viewWillAppear;

/**
 自定义UserAgent
 */
- (void)setCustomUserAgent:(nullable NSString *)customUserAgent;

///兼容UIWebview同名方法
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;

/**
 清除缓存

 WKWebsiteDataTypeDiskCache,
 WKWebsiteDataTypeOfflineWebApplicationCache,
 WKWebsiteDataTypeMemoryCache,
 WKWebsiteDataTypeLocalStorage,
 WKWebsiteDataTypeCookies,
 WKWebsiteDataTypeSessionStorage,
 WKWebsiteDataTypeIndexedDBDatabases,
 WKWebsiteDataTypeWebSQLDatabases
 @param dataTypes 传nil则表示所有类型：[WKWebsiteDataStore allWebsiteDataTypes]
 @param complete 完成回调
 */
+ (void)cleanCache:(nullable NSSet *)dataTypes complete:(dispatch_block_t)complete;

/**
 wkwebview 预加载
 */
+ (void)prepareWebView;

@end

NS_ASSUME_NONNULL_END
